


enum FGuiType{
    GButton = "GButton",
    GComboBox = "GComboBox",
    GComponent = "GComponent",
    GGraph = "GGraph",
    GGroup = "GGroup",
    GImage = "GImage",
    GLabel = "GLabel",
    GList = "GList",
    GLoader = "GLoader",
    GLoader3D = "GLoader3D",
    GMovieClip = "GMovieClip",
    GProgressBar = "GProgressBar",
    GRichTextField = "GRichTextField",
    GScrollBar = "GScrollBar",
    GSlider = "GSlider",
    GTextField = "GTextField",
    GTextInput = "GTextInput",
    Transition = "Transition",
    Controller = "Controller",
}

export class CommonTools {
    public static customPropsData: CS.FairyEditor.CustomProps

    /**
     * 是否是 Fgui 的类型
     * @param type 
     * @returns 
     */
    public static checkIsFguiType(type: string) {
        return type in FGuiType;
    }

    public static getCustomPropertyData() : CS.FairyEditor.CustomProps{
        if (!this.customPropsData) this.customPropsData = <CS.FairyEditor.CustomProps>CS.FairyEditor.App.project.GetSettings("CustomProperties");
        return this.customPropsData;
    }
    /**
     * 获取项目的自定义属性
     * @param key 
     * @returns 
     */
    public static getCustomSetKeyValue(key: string) {
        let dic = this.getCustomPropertyData();
        let data = dic.elements.ContainsKey(key) ? dic.elements.get_Item(key) : undefined;
        if(data == undefined){
            console.log(`未找到 ${key} 的配置项，请检查项目的自定义属性中是否有配置`);
        }
        return data
    }

    /**
     * 判断是否是需要生成到 ViewID中的ui 组件
     * @param uiName 
     */
    public static checkIsViewUI(uiName:string) : boolean{
        return uiName.endsWith("View")
    }
    /** UIPkg  ts脚本的保存路径 */
    public static getUIPkgPath(exportCodePath:string) : string{
        let outPath = "";
        let ctPath = this.getCustomSetKeyValue("UIPkgScriptPath");
        if(ctPath){
            let idx = exportCodePath.indexOf(`..\\`);
            if (idx > 0) {
                outPath = exportCodePath.substring(0, idx) + ctPath;
            }
        }else{
            outPath = exportCodePath + '/' + 'UIPkg.ts';
        }
        return outPath;
    }
    /** UIConst  ts脚本的保存路径 */
    public static getUIConstPath(exportCodePath:string) : string{
        let outPath = "";
        let ctPath = this.getCustomSetKeyValue("UIConstScriptPath");
        if(ctPath){
            let idx = exportCodePath.indexOf(`..\\`);
            if (idx > 0) {
                outPath = exportCodePath.substring(0, idx) + ctPath;
            }
        }else{
            outPath = exportCodePath + '/' + 'UIConst.ts';
        }
        return outPath;
    }
    /**获取生成的 UIConst 文件中的 import 导入对应的 ts脚本的路径 */
    public static getUIConstImportPath() : string{
        let path = this.getCustomSetKeyValue("BinderImportPath");
        if(path){
            return path;
        }else{
            return ""
        }
    }
    /** ViewId  ts脚本的保存路径 */
    public static getViewIdPath(exportCodePath:string) : string{
        let outPath = "";
        let ctPath = this.getCustomSetKeyValue("ViewIDScriptPath");
        if(ctPath){
            let idx = exportCodePath.indexOf(`..\\`);
            if (idx > 0) {
                outPath = exportCodePath.substring(0, idx) + ctPath;
            }
        }else{
            outPath = exportCodePath + '/' + 'ViewID.ts';
        }
        return outPath;
    }

} 